package com.zzptc.myk.myapplication;

import android.content.Context;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;

import java.util.ArrayList;


public class FirstFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_first, container, false);
        LineChart lineChart=view.findViewById(R.id.line_Chart);
        ArrayList<Entry> list=new ArrayList<>();
        list.add(new Entry(1,2));
        list.add(new Entry(4,3));
        list.add(new Entry(3,4));
        list.add(new Entry(4,8));
        list.add(new Entry(7,4));


        ArrayList<Entry> list1=new ArrayList<>();
        list1.add(new Entry(1,4));
        list1.add(new Entry(2,5));
        list1.add(new Entry(3,7));
        list1.add(new Entry(4,3));
        list1.add(new Entry(7,9));


        LineDataSet lineDataSet=new LineDataSet(list,null);
        LineDataSet lineDataSet1=new LineDataSet(list1,null);

        //颜色
        lineDataSet.setCircleColor(Color.YELLOW);

        lineDataSet1.setColor(Color.RED);
        //线宽度
        lineDataSet.setLineWidth(2f);


//        ArrayList<ILineDataSet> lineDataSets=new ArrayList<>();
//        lineDataSets.add(lineDataSet);
//        lineDataSets.add(lineDataSet1);


        LineData lineData=new LineData(lineDataSet);
        lineData.addDataSet(lineDataSet);
        lineData.addDataSet(lineDataSet1);
        lineChart.setData(lineData);
        XAxis xAxis = lineChart.getXAxis();


    //设置x轴
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        return view;
    }
}
